package com.example.study.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
//开启swagger
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket docket1(){
        return new Docket(DocumentationType.SWAGGER_2).groupName("A");
    }
    /**
     * 配置了swagger的Docket的bean实例,用Docket对象接管了他原来的默认配置ApiInfo
     * @return
     */
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("喜欢多云的季节")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.example.study.controller"))//扫描那些包
                .paths(PathSelectors.any())//任何路径都可以
                .build();
    }

    /**
     * 配置swagger信息apiInfo() 里面要传入一个 apiInfo
     */

    private ApiInfo apiInfo() {

        //作者信息
        Contact contact = new Contact("云间月", "https://www.baidu.com/", "3193920282@qq.com");

        return new ApiInfo(
                "swagger 学习日记",
                "喜欢多云的季节",
                "1.0",
                "https://www.baidu.com/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}
